import { EJewel } from "../../../../../Message/Public/EJewel";
import { MWPropertyItemData } from "../../magicWeapon/data/MWPropertyItemData";
import { GameDefConfig } from "../../../resource/GameDefConfig";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FahunListPanel } from "../../fahun/FahunListPanel";
import { Language } from "../../../../../extend/language/Language";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { FabaoItem } from "./FabaoItem";
import { BgItem } from "../../common/BgItem";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ESex } from "../../../../../Message/Public/ESex";
import { SPlayerItemUpdate } from "../../../../../Message/Game/SPlayerItemUpdate";
import { ItemData } from "../../../resource/info/ItemData";
import { Cache } from "../../../cache/Cache";
import { MagicWeaponUtil } from "../../magicWeapon/MagicWeaponUtil";
import { MagicWeaponTool } from "../../magicWeapon/MagicWeaponTool";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { FabaoRoleMan } from "../../../../../ImagesConst/FabaoRoleMan";
type int = number;
//class FabaoRolePanel
    
    export  class FabaoRolePanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initData();
            this.createChildren();
            return;
        }

        public updateFahunList(arg1: Array<any>): void
        {
            this._fahunListPanel.updateFahunList(arg1);
            return;
        }

        public showLinkTxt(arg1: Boolean): void
        {
            this._linkTxt.visible = arg1;
            this._fahunListPanel.isClickOpen = arg1;
            return;
        }

        /* internal  */initData(): void
        {
            var loc1=null;
            var loc2=null;
            this._dicPosItem = new Map<any, any> /* flash.utils.Dictionary */();
            this._fabaoAttriData = new Array<any>();
            var loc3=[0, EJewel._EJewelLife, EJewel._EJewelPhysicalDefense, EJewel._EJewelMagicDefense, EJewel._EJewelToughness, EJewel._EJewelJouk, EJewel._EJewelRelief, EJewel._EJewelPass, EJewel._EJewelWuXingDefenseGold, EJewel._EJewelWuXingDefenseWood, EJewel._EJewelWuXingDefenseWater, EJewel._EJewelWuXingDefenseFire, EJewel._EJewelWuXingDefenseEarth];
            var loc4=0;
            while (loc4 < loc3.length) 
            {
                loc1 = new MWPropertyItemData();
                loc1.type = loc3[loc4];
                loc2 = GameDefConfig.instance.getItem("MagicWeapon", loc1.type);
                loc1.name = loc2.name;
                loc1.property = 0;
                this._fabaoAttriData.push(loc1);
                ++loc4;
            }
            return;
        }

        protected createChildren(): void
        {
            this.mouseEnabled = false;
            ObjCreate.createBg(6, 2, 287, 343, this);
            ObjCreate.createBg(296, 2, 102, 343, this);
            ObjCreate.createBitmap(ImagesConst.fairylandPattern, 296, 2, this);
            ObjCreate.createBg(6, 348, 392, 52, this);
            this._bmpBg = ObjCreate.createBitmap("", 7, 5, this);
            this._bmpTextAttri = ObjCreate.createBitmap("", 305, 5, this);
            this._bmpTextSkill = ObjCreate.createBitmap("", 10, 353, this);
            this._bmpRole = ObjCreate.createBitmap("", 82, 85, this);
            var loc1=GlobalStyle.textFormat6;
            loc1.underline = true;
            var loc2=GlobalStyle.textFormat6;
            loc2.leading = 9;
            this._tfDes = ObjCreate.createGTextField("", 305, 32, 90, 320, this, loc2);
            this._tfDes.multiline = true;
            this._tfDes.wordWrap = true;
            this._fabaoItem1 = this.createFabaoItem(140, 53, true, 19);
            this._fabaoItem2 = this.createFabaoItem(235, 128, true, 20);
            this._fabaoItem3 = this.createFabaoItem(208, 250, false, 21);
            this._fabaoItem4 = this.createFabaoItem(59, 250, false, 22);
            this._fabaoItem5 = this.createFabaoItem(30, 128, false, 23);
            this._fahunListPanel = new FahunListPanel();
            this._fahunListPanel.x = 85;
            this._fahunListPanel.y = 358;
            this.addChild(this._fahunListPanel);
            this._linkTxt = ObjCreate.createGTextField("", 330, 365, 100, 20, this);
            this._linkTxt.multiline = true;
            this._linkTxt.htmlText = Language.getString(58027);
            this._linkTxt.addEventListener(flash.events.TextEvent.LINK, this.onOpenFahunHandler);
            LoaderHelp.addResCallBack(ResFileConst.fabaoRole, this.onResCompl);
            this.updateDes();
            return;
        }

        /* internal  */createFabaoItem(arg1: number, arg2: number, arg3: Boolean, arg4: int): FabaoItem
        {
            var loc1=null;
            (loc1 = new FabaoItem()).x = arg1;
            loc1.y = arg2;
            loc1.isOpen = arg3;
            loc1.posIndex = arg4;
            this.addChild(loc1);
            this._dicPosItem[arg4] = loc1;
            return loc1;
        }

        public updateAmuletHoleNum(arg1: int): void
        {
            var loc2=null;
            var loc1=0;
            loc1 = 0;
            while (loc1 < 5) 
            {
                loc2 = this._dicPosItem[19 + loc1];
                if (loc1 < arg1) 
                {
                    loc2.isOpen = true;
                }
                loc2.updateView();
                ++loc1;
            }
            return;
        }

        /* internal  */createSkillItem(arg1: number, arg2: number, arg3: Object /* flash.display.DisplayObjectContainer */=null, arg4: Boolean=false): BgItem
        {
            var loc2=null;
            var loc3=null;
            var loc1=new BgItem();
            ObjCreate.setObjAttri(loc1, arg1, arg2, -1, -1, arg3);
            if (!arg4) 
            {
                (loc2 = GlobalStyle.textFormatGray).leading = 2;
                (loc3 = ObjCreate.createTextField(Language.getString(30294), 4, 3, 32, 32, loc1, loc2)).multiline = true;
                loc3.wordWrap = true;
            }
            return loc1;
        }

        /* internal  */onResCompl(): void
        {
            this._isResCompl = true;
            this._bmpBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.FabaoRoleBg);
            this._bmpTextAttri.bitmapData = GlobalClass.getBitmapData(ImagesConst.FabaoRoleTextAttri);
            this._bmpTextSkill.bitmapData = GlobalClass.getBitmapData(ImagesConst.FabaoRoleTextSkil);
            this.updateSexView();
            return;
        }

        /* internal  */updateSexView(): void
        {
            var loc1=this._sex != ESex._ESexMan ? ImagesConst.FabaoRoleWomen : FabaoRoleMan;
            this._bmpRole.bitmapData = GlobalClass.getBitmapData(loc1);
            return;
        }

        /* internal  */updateDes(): void
        {
            this._tfDes.htmlText = this.getAttriDes();
            return;
        }

        public updateData(arg1: Array<any>, arg2: int=0, arg3: Boolean=true): void
        {
            var loc1=null;
            var loc2=null;
            var loc6=undefined;
            var loc7=null;
            var loc8=0;
            var loc9=null;
            var loc10=null;
            var loc11=null;
            var loc12=null;
            this.setIsSelf(arg3);
            this.clearLocalData();
            this._sex = arg2;
            if (this._isResCompl) 
            {
                this.updateSexView();
            }
            var loc3=new Array<any>();
            var loc4=new Map<any, any> /* flash.utils.Dictionary */();
            var loc5=0;
            while (loc5 < arg1.length) 
            {
                loc7 = arg1[loc5];
                loc8 = -1;
                if (typeof loc7 === "splayeritemupdate") 
                {
                    loc9 = loc7 as SPlayerItemUpdate;
                    loc1 = new ItemData(loc9.playerItem);
                    loc8 = loc9.posIndex;
                }
                else if (typeof loc7 === "itemdata") 
                {
                    loc1 = loc7 as ItemData;
                    loc8 = Cache.instance.pack.rolePackCache.getIndexByUid(loc1.uid);
                }
                if (loc1) 
                {
                    loc10 = MagicWeaponUtil.analyseProperty(loc1);
                    var loc13=0;
                    var loc14=loc10;
                    for(loc11 of loc14) 
                    {
                        var loc15=0;
                        var loc16=this._fabaoAttriData;
                        for(loc12 of loc16) 
                        {
                            if (loc12.type != loc11.type) 
                            {
                                continue;
                            }
                            loc12.property = loc12.property + (loc11.property + Math.floor(MagicWeaponTool.getStrenthenAdd(loc1) * loc11.property / 100));
                        }
                    }
                    if (loc2 = this._dicPosItem[loc8]) 
                    {
                        loc3.push(loc8);
                        loc2.itemData = loc1;
                    }
                }
                ++loc5;
            }
            loc13 = 0;
            loc14 = this._dicPosItem;
            for (loc6 in loc14) 
            {
                if (loc3.indexOf(int(loc6)) != -1) 
                {
                    continue;
                }
                (this._dicPosItem[loc6] as FabaoItem).itemData = null;
            }
            this.updateDes();
            return;
        }

        /* internal  */setIsSelf(arg1: Boolean): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._dicPosItem;
            for(loc1 of loc3) 
            {
                loc1.isSelf = arg1;
            }
            return;
        }

        /* internal  */clearLocalData(): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._fabaoAttriData;
            for(loc1 of loc3) 
            {
                loc1.property = 0;
            }
            return;
        }

        /* internal  */getAttriDes(): string
        {
            var loc2=null;
            var loc1="";
            var loc3=0;
            var loc4=this._fabaoAttriData;
            for(loc2 of loc4) 
            {
                loc1 = loc1 + (loc2.propertyHtmlDec + "<br>");
            }
            return loc1;
        }

        /* internal  */onOpenFahunHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.FahunShowTab, {"operIndex": 0, "itemIndex": 0}));
            return;
        }

        /* internal */ /* var */_bmpBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpTextAttri: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpTextSkill: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpRole: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_tfDes: GTextFiled;

        /* internal */ /* var */_dicPosItem: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_fabaoItem1: FabaoItem;

        /* internal */ /* var */_fabaoItem2: FabaoItem;

        /* internal */ /* var */_fabaoItem3: FabaoItem;

        /* internal */ /* var */_fabaoItem4: FabaoItem;

        /* internal */ /* var */_fabaoItem5: FabaoItem;

        /* internal */ /* var */_fahunListPanel: FahunListPanel;

        /* internal */ /* var */_linkTxt: GTextFiled;

        /* internal */ /* var */_isResCompl: Boolean=false;

        /* internal */ /* var */_sex: int=0;

        /* internal */ /* var */_fabaoAttriData: Array<any>;
    }
